package com.collect.collectclient.collect.controller;

import com.collect.collectclient.base.common.Result;
import com.collect.collectclient.collect.dto.ComputerInfo;
import com.collect.collectclient.collect.service.SysInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zhang
 */
@RestController
@RequestMapping("/info")
public class CollectController {

    @Autowired
    private SysInfoService sysInfoService;

    @ApiOperation(value = "获取cpu数据", notes = "获取cpu数据")
    @RequestMapping(value = "/getCpuInfo", method = RequestMethod.POST)
    public Result getCpuInfo(@RequestBody Map map) {
        String cpuINfo = sysInfoService.getCPURate();
        return Result.ok(cpuINfo);
    }

    @ApiOperation(value = "获取内存信息", notes = "获取内存信息")
    @RequestMapping(value = "/getMemory", method = RequestMethod.POST)
    public Result getMemory(@RequestBody Map map) {
        String cpuINfo = sysInfoService.getMemoryRate();
        return Result.ok(cpuINfo);
    }

    @ApiOperation(value = "获取线程数", notes = "获取线程数")
    @RequestMapping(value = "/getThreadCount", method = RequestMethod.POST)
    public Result getThreadCount(@RequestBody Map map) {
        Integer cpuINfo = sysInfoService.getThreadCount();
        return Result.ok(cpuINfo);
    }

    @ApiOperation(value = "获取网络情况", notes = "获取网络情况")
    @RequestMapping(value = "/getNetWork", method = RequestMethod.POST)
    public Result getNetWork(@RequestBody Map map) {
        String cpuINfo = sysInfoService.getNetworkThroughput();
        return Result.ok(cpuINfo);
    }


    @ApiOperation(value = "获取线程数", notes = "获取线程数")
    @RequestMapping(value = "/getComputer", method = RequestMethod.POST)
    public Result getComputer(@RequestBody Map map) throws Exception{
        ComputerInfo info=sysInfoService.getComputerInfo();
        return Result.ok(info);
    }
}
